#include "resp.h"

#include <stdio.h>
#include <string.h>

#include "util.h"

#define SERVER_STRING "Server: nano-httpd/0.1.0\r\n"

void resp_200(int sock, const char *file)
{
    (void)file;
    const char *buf = "HTTP/1.0 200 OK\r\n"
                      "Content-Type: text/html\r\n"
                      "\r\n";
    send_all(sock, buf, strlen(buf));
}

void resp_400(int sock)
{
    const char *buf = "HTTP/1.0 400 Bad Request\r\n"
                      "Content-type: text/html\r\n"
                      "\r\n"
                      "<P>Your browser sent a bad request, "
                      "such as a POST without a Content-Length.\r\n";
    send_all(sock, buf, strlen(buf));
}

void resp_404(int sock)
{
    const char *buf = "HTTP/1.0 404 Not Found\r\n"
                      "Content-Type: text/html\r\n"
                      "\r\n"
                      "<html><head><title>404 Not Found</title></head><body>\r\n"
                      "<h1>Not Found</h1>\r\n"
                      "<p>The requested URL was not found on this server.</p>\r\n"
                      "</body></html>\r\n";
    send_all(sock, buf, strlen(buf));
}

void resp_500(int sock)
{
    const char *buf = "HTTP/1.0 500 Internal Server Error\r\n"
                      "Content-type: text/html\r\n"
                      "\r\n"
                      "<P>Error prohibited CGI execution.\r\n";
    send_all(sock, buf, strlen(buf));
}

void resp_501(int sock)
{
    const char *buf = "HTTP/1.0 501 Method Not Implemented\r\n"
                      "Content-Type: text/html\r\n"
                      "\r\n"
                      "<html><head><title>Method Not Implemented</title></head>\r\n"
                      "<body><p>HTTP request method not supported.\r\n"
                      "</body></html>\r\n";
    send_all(sock, buf, strlen(buf));
}
